import 'package:flutter/material.dart';
import 'package:top_foundation/utils/theme/theme.dart';

import '../util.dart';

class DialogInputBottom extends StatelessWidget {
  const DialogInputBottom({
    super.key,
    required this.title,
    required this.onChanged,
    this.bgColor,
    this.conditionDismiss,
  });
  final String title;
  final Color? bgColor;
  final ValueChanged<String> onChanged;
  final BoolResultCallback? conditionDismiss;
  @override
  Widget build(BuildContext context) {
    String text = '';
    return Container(
      decoration: BoxDecoration(
        color: bgColor ?? Colors.white,
        borderRadius: const BorderRadius.vertical(top: Radius.circular(20)),
      ),
      child: SafeArea(
        top: false,
        child: Column(
          children: [
            Container(
              height: 50,
              alignment: Alignment.center,
              child: Text(
                title,
                style: ITheme.text.titleMedium,
              ),
            ),
            Padding(
              padding: EdgeInsets.symmetric(horizontal: 20.r),
              child: UITextField(
                hintText: '请输入',
                onChanged: (val) {
                  text = val;
                  onChanged(val);
                },
              ),
            ),
            BtnBar(onTap: (p0) async {
              if (p0 == 0) {
                Get.back();
              } else {
                if (text.isEmpty) return;
                if (conditionDismiss != null) {
                  if (conditionDismiss!()) {
                    Get.back(result: 1);
                  }
                } else {
                  Get.back(result: 1);
                }
              }
            }),
          ],
        ),
      ),
    );
  }
}
